1 00:00:00,150 --> 00:00:00,420 All right. 2 00:00:00,500 --> 00:00:06,350 So I'm in my battle Royale arena area, and I wanted to take a quick look at my battle manager, point 3 00:00:06,350 --> 00:00:07,250 some things out. 4 00:00:07,250 --> 00:00:09,290 So if you forgot what a battle manager is. 5 00:00:09,290 --> 00:00:10,220 Server script service. 6 00:00:10,220 --> 00:00:11,390 Battle manager. 7 00:00:11,780 --> 00:00:12,050 All right. 8 00:00:12,050 --> 00:00:16,070 So what happens when we get teleported to our world, to our arena? 9 00:00:16,190 --> 00:00:22,760 The server will be provisioned, the players will enter the game, and then this script is read. 10 00:00:22,820 --> 00:00:27,710 We go down here and at the bottom, boom, we fire off the battle. 11 00:00:27,710 --> 00:00:31,640 We get to here, wait three seconds, and then we have our countdown. 12 00:00:31,640 --> 00:00:32,960 Beep, beep, beep, beep, beep. 13 00:00:32,990 --> 00:00:36,260 If other people are joining the game, that's fine. 14 00:00:36,260 --> 00:00:38,000 They're in the battle, too. 15 00:00:38,300 --> 00:00:44,810 So we're going to do here is I'm going to set some flags and then I'm going to start and stop the battle 16 00:00:44,840 --> 00:00:49,190 based on whether there's players present or if everybody leaves that way. 17 00:00:49,190 --> 00:00:53,900 We're not relying on the server to shut down, to start up and shut down our game. 18 00:00:54,080 --> 00:00:59,240 Let's just go ahead and do a local high's began. 19 00:00:59,390 --> 00:01:01,700 I'm going to make that false, right? 20 00:01:01,710 --> 00:01:08,010 The battle has not began, but when we call battle, it has. 21 00:01:08,040 --> 00:01:11,010 We'll say highs began equals true. 22 00:01:11,730 --> 00:01:12,030 All right. 23 00:01:12,030 --> 00:01:13,230 So the battle started. 24 00:01:13,230 --> 00:01:14,310 We're getting our countdown. 25 00:01:14,340 --> 00:01:16,200 Beep, beep, beep, beep. 26 00:01:16,380 --> 00:01:17,550 Let's go down here. 27 00:01:17,550 --> 00:01:21,690 Now, this while loop is going to run until is ended is set. 28 00:01:21,720 --> 00:01:28,110 True, there's a winner, but it's possible to not have a winner because we have one second delay in 29 00:01:28,110 --> 00:01:28,740 here. 30 00:01:29,100 --> 00:01:30,720 Maybe everybody left within that. 31 00:01:30,720 --> 00:01:32,730 Second, there might have been two people left. 32 00:01:32,760 --> 00:01:33,240 Boom. 33 00:01:33,240 --> 00:01:34,740 They're both gone at the same time. 34 00:01:34,740 --> 00:01:36,600 So it's fine. 35 00:01:36,600 --> 00:01:38,970 The server will shut down, the loop will stop. 36 00:01:38,970 --> 00:01:40,920 But let's just go ahead and turn it off. 37 00:01:40,920 --> 00:01:44,040 Let's get down to here. 38 00:01:44,640 --> 00:01:45,020 All right. 39 00:01:45,020 --> 00:01:46,970 We can do it above our print statement. 40 00:01:47,420 --> 00:01:50,160 Let me scroll a little bit so it's closer to the center. 41 00:01:50,180 --> 00:01:57,920 I'm going to say if num, which is the number of players, is less than or equal to one, then let's 42 00:01:57,920 --> 00:02:00,440 go ahead and make sure the battle is ended. 43 00:02:00,470 --> 00:02:01,040 Is ended. 44 00:02:01,040 --> 00:02:01,880 Is true. 45 00:02:02,150 --> 00:02:05,510 And then we'll say has begun is false. 46 00:02:07,100 --> 00:02:07,790 All right. 47 00:02:07,820 --> 00:02:16,250 Now here in add player to game, this is going to fire every time someone joins the game. 48 00:02:16,250 --> 00:02:22,070 And if we teleport ten people over even at the same time which is what we're doing, this is still going 49 00:02:22,070 --> 00:02:23,750 to fire at different times. 50 00:02:23,750 --> 00:02:28,010 People are going to show up at different times depending on your network, depending on a lot of things. 51 00:02:28,010 --> 00:02:33,470 So I want to start the battle here because I want to start the battle when there's people in the world, 52 00:02:33,470 --> 00:02:35,810 I just want to make sure and start at once. 53 00:02:35,810 --> 00:02:41,420 So I'm going to say, if not has begun, then we'll do our battle. 54 00:02:41,420 --> 00:02:46,530 But I think I'm going to spawn it so I don't tie up the thread in battle. 55 00:02:46,530 --> 00:02:47,670 You don't have to spawn it. 56 00:02:47,670 --> 00:02:48,960 You could just do the battle here. 57 00:02:48,960 --> 00:02:51,720 But I decided to do that. 58 00:02:51,720 --> 00:02:52,920 All right, Now we can get rid of this. 59 00:02:52,920 --> 00:02:54,690 We don't need this now. 60 00:02:54,690 --> 00:03:00,180 We don't have to worry about our start up and stopping of the server to control the start and stop of 61 00:03:00,180 --> 00:03:00,900 the battle. 62 00:03:00,900 --> 00:03:02,610 Although the other way will work fine. 63 00:03:02,610 --> 00:03:04,350 So you're welcome to use either one. 64 00:03:04,350 --> 00:03:08,250 But if you're curious, this is how you do it with code rather than the server.